﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
/// <summary>
/// 功能：显示选中物体以及其子物体
/// </summary>
public class SetChildActive : MonoBehaviour {

    [MenuItem("GameObject/显示所有子物体和父物体", priority = -1)]
    public static void SetActiveAllChild()
    {
        GameObject selectionObj = Selection.activeTransform.gameObject;
        selectionObj.SetActive(true);

        ShowChild(selectionObj);
        ShowParent(selectionObj);
    }
    static void ShowChild(GameObject obj)
    {
        for (int i = 0; i < obj.transform.childCount; i++)
        {
            GameObject child = obj.transform.GetChild(i).gameObject;

            child.SetActive(true);

            ShowChild(child);
        }
    }

    static void ShowParent(GameObject obj)
    {
        if (obj.transform.parent != null)
        {
            obj.transform.parent.gameObject.SetActive(true);
            ShowParent(obj.transform.parent.gameObject);
        }
    }

}
